package com.sctvcloud.zhaohua_sd.ui.adapter.holder;

import android.content.Context;
import android.text.TextUtils;
import android.util.Pair;
import android.view.View;
import android.widget.ImageView;

import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.sctvcloud.zhaohua_sd.R;
import com.sctvcloud.zhaohua_sd.beans.NewsItem;
import com.sctvcloud.zhaohua_sd.ui.utils.GlideUtil;
import com.sctvcloud.zhaohua_sd.ui.utils.SkipUtil;
import com.sctvcloud.zhaohua_sd.ui.utils.UIUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/24 0024.
 */

public class TopicDetailVideoHolder extends BaseAbsHolder<NewsItem> implements View.OnClickListener {
    @BindView(R.id.item_search_result_article_content_img)
    protected CustomEXImageView img;
    @BindView(R.id.item_search_result_article_content_title)
    protected CustomFontTextView title;
    @BindView(R.id.item_search_result_article_content_time)
    protected CustomFontTextView time;
    @BindView(R.id.item_search_result_article_content_lable)
    protected CustomFontTextView lable;
    @BindView(R.id.item_search_result_article_content_type)
    protected ImageView type;
    @BindView(R.id.item_search_result_article_content_length)
    protected CustomFontTextView playTime;
    @BindView(R.id.item_search_result_article_content_divider)
    protected View divider;
    @BindView(R.id.item_search_result_article_content_views)
    protected CustomFontTextView views;
    private NewsItem newsItem;
    private List<NewsItem> list;
    public int video_size = 0;

    public TopicDetailVideoHolder(Context context, View itemView) {
        super(context, itemView);
        //this.list = list;
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(NewsItem newsItem) {
        this.newsItem = newsItem;
        title.setText(!TextUtils.isEmpty(newsItem.getNewsTitle()) ? newsItem.getNewsTitle() : "");
        time.setText(!TextUtils.isEmpty(newsItem.getPubTime()) ? DateUtils.formatDate(DateUtils.getDataDate(newsItem), "MM-dd") : "");
        views.setVisibility(View.VISIBLE);
        views.setText(UIUtils.getReadingNumber(newsItem.getReadCount()));
        lable.setText(!TextUtils.isEmpty(newsItem.getLable()) ? newsItem.getLable() : "");

        if (!TextUtils.isEmpty(newsItem.getNewsImage())) {
            GlideUtil.getGlideWithSmall169Def(context, newsItem.getNewsImage()).into(img);
            img.setVisibility(View.VISIBLE);
        } else {
            img.setImageResource(R.mipmap.icon_def_16_9_s);
            img.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(newsItem.getNewsMediaLength())) {
            playTime.setVisibility(View.VISIBLE);
            playTime.setText(newsItem.getNewsMediaLength());
        } else {
            playTime.setVisibility(View.GONE);
        }
        if (newsItem.getNewsType() == 2) { //音频
            type.setImageResource(R.mipmap.icon_home_voice);
            type.setVisibility(View.VISIBLE);
        }else if (newsItem.getNewsType() == 3) {   //视频
            type.setImageResource(R.mipmap.icon_home_play);
            type.setVisibility(View.VISIBLE);
        }else {
            type.setVisibility(View.GONE);
        }
        if (newsItem.isLastItem()) {
            divider.setVisibility(View.GONE);
        } else {
            divider.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onClick(View v) {
        SkipUtil.skipWithNewsItem(context, newsItem,new HashMap<String, String>());
    }
}
